/************************************************************************/
/*    author  vinee.han
/*    time    2015/06/05
/*    wikioi                                                                     */
/************************************************************************/


#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void fcino()
{
    freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}

void fexit()
{
    fclose(stdin);
	fclose(stdout);
}

struct BTree
{
	int data,left,right;
}Tr[100];

int height,width[1000];
/*BTree* create(int ch)
{
	BTree* root;
	if (ch == 0)
	{
		return NULL;
	}
	else
	{
		root = new BTree;
		root->data = ch;
		root->lch = create(ch);
		root->rch = create(ch);
		return root;
	}
}*/

void createBT(int data,int lc,int rc)
{
	if (data == 0)
	{
		return;
	}
	else
	{
	    Tr[data].data = data;
		Tr[data].left = lc;
		Tr[data].right = rc;
	}
}

int BTH(int data,int h)
{	
	if(Tr[data].data == 0)
	{
	    h = 0;
	}
	else
	{
		width[h] = width[h]+1;
		int left_h = BTH(Tr[data].left,h+1);
		int right_h = BTH(Tr[data].right,h+1);
		h = 1 + max(left_h,right_h);
	}
	return h;
}

int main()
{
	int n,a,b;
	//fcino();
	cin>>n;
	for(int i=1;i<=n;i++)
	{
	    cin>>a>>b;
		createBT(i,a,b);
	}
	int maxw = 0;
	height = BTH(1,1);
	for (int i=0;i<1000;i++)
	{
		if (maxw<width[i])
		{
			maxw = width[i];
		}
	}
	cout<<maxw<<" "<<height<<endl;
	//fexit();
	return 0;
}